home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / c-tools / c_examples / slider / slider_example.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-02  |  2.4 KB  |  104 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. // Led Class Example
  3. // 5.18.96 Deryk Robosson
  4.  
  5. //////////////////////////////////////////////////////////////////////////////
  6. // Includes
  7. #include "aframe:include/amigaapp.hpp"
  8. #include "aframe:include/window.hpp"
  9. #include "aframe:include/button.hpp"
  10. #include "aframe:include/rect.hpp"
  11. #include "aframe:include/led.hpp"
  12. #include "aframe:include/slider.hpp"
  13.  
  14. //////////////////////////////////////////////////////////////////////////////
  15. // ControlWindow Class Definition
  16.  
  17. class ControlWindow : public AFWindow
  18.  
  19. {
  20. public:
  21.     ControlWindow();
  22.     virtual void OnGadgetUp(LPIntuiMessage imess);
  23.     virtual void OnNewSize(LPIntuiMessage imess);
  24.     virtual ULONG WindowFlags();
  25.  
  26.     AFLed       led;
  27.     AFSlider    slider;
  28.     AFButton    up;
  29.     AFButton    down;
  30.  
  31.     ULONG       value;
  32. };
  33.  
  34. //////////////////////////////////////////////////////////////////////////////
  35. // ControlWindow Implementation routines
  36.  
  37. ControlWindow::ControlWindow()
  38.     :value(0)
  39. {
  40. }
  41.  
  42. void ControlWindow::OnGadgetUp(LPIntuiMessage imess)
  43. {
  44.     switch(((struct Gadget*)imess->IAddress)->GadgetID) {
  45.     case 100:   // up gadget
  46.         if(++value>99)
  47.             value=0;
  48.         led.SetDigits(0,value);
  49.         slider.SetPos(value);
  50.         break;
  51.     case 101:   // down gadget
  52.         if(--value<0)
  53.             value=99;
  54.         led.SetDigits(0,value);
  55.         slider.SetPos(value);
  56.         break;
  57.     case 102:   // slider gadget
  58.         led.SetDigits(0,(value=slider.CurrentPos());
  59.         break;
  60.     default:
  61.         AFWindow::OnGadgetUp(imess);
  62.         break;
  63.     }
  64. }
  65.  
  66. void ControlWindow::OnNewSize(LPIntuiMessage imess)
  67. {
  68.     led.RefreshImage();
  69. }
  70.  
  71. ULONG ControlWindow::WindowFlags()
  72. {
  73.     return (AFWindow::WindowFlags() | WFLG_GIMMEZEROZERO);
  74. }
  75.  
  76. //////////////////////////////////////////////////////////////////////////////
  77. // MAIN
  78.  
  79. void main()
  80. {
  81.     AFAmigaApp theApp;
  82.     ControlWindow win;
  83.     AFRect rect(10,10,410,310);
  84.  
  85.     win.Create(&theApp,&rect,"AFrame Led Example");
  86.  
  87.     rect.SetRect(0,0,100,100);
  88.     win.led.Create(&win,&rect,99);
  89.  
  90.     rect.SetRect(100,0,150,30);
  91.     win.up.Create("Increase",&win,&rect,100);
  92.  
  93.     rect.SetRect(152,0,202,30);
  94.     win.down.Create("Decrease",&win,&rect,101);
  95.  
  96.     rect.SetRect(204,0,234,100);
  97.     win.slider.Create(&win,&rect,(ULONG)102,(UWORD)NULL,100,99,1);
  98.  
  99.  
  100.     win.RefreshGadgets();
  101.  
  102.     theApp.RunApp();
  103. }
  104.